package com.hzit.test;

import com.hzit.dao.UserDao;
import com.hzit.dao.impl.UserDaoImpl;
import com.hzit.dao.proxy.UserDaoImplDynamicProxyCGLIB;
import com.hzit.dao.proxy.UserDaoImplDynamicProxyJDK;
import com.hzit.dao.proxy.UserDaoImplStaticProxy;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

/**
 * 类名：
 * 作者：WF
 * 功能：
 */

public class UserDaoProxy {
	private UserDao userDao1 = new UserDaoImplStaticProxy();
	private UserDaoImplDynamicProxyJDK userDao2 = new UserDaoImplDynamicProxyJDK();
	private UserDaoImplDynamicProxyCGLIB proxyCGLIB = new UserDaoImplDynamicProxyCGLIB();
	//1. 静态代理测试
	@Test
	public void test01(){
		userDao1.add();
		System.out.println("-----------------------------");
		userDao1.query();
	}

	//2.  JDK动态代理测试
	@Test
	public void test02(){
		//2.1 创建代理对象
		UserDao proxy = userDao2.createProxy();
		//2.2 调用方法
		proxy.add();
		System.out.println("---------------------------");
		proxy.query();
	}

	//3.  CGLIB动态代理测试
	@Test
	public void test03(){
		//3.1 创建代理对象
		UserDaoImpl proxy = proxyCGLIB.createProxy();
		//3.2 调用代理对象的方法
		proxy.add();
		System.out.println("------------------------------");
		proxy.query();
	}

}
